from monitor import limit_up,load_prev_data
from datetime import datetime
import tushare as ts
import pandas as pd
from utils import read_config,get_directory
import os


config = read_config()
_base_directory = config.get('settings','base_file')
_daily_directory = config.get('settings','monitor_file')
print('start monitor big')
old = load_prev_data.load_data()
rs_array =[]
# 东财数据
df = ts.realtime_list(src='dc')
for index, row in df.iterrows():
    if not row['TS_CODE'].endswith(".BJ") and row['PCT_CHANGE'] > 6.5 and row['PCT_CHANGE'] < 20.5:
        _rs = limit_up.check_big_trend(row['TS_CODE'],row['VOLUME'],old)
        if _rs != '':
            rs_array.append([row['TS_CODE'],row['NAME'],row['PRICE'],row['PCT_CHANGE'],row['VOL_RATIO'],row['TURNOVER_RATE'],_rs])
rs = pd.DataFrame(rs_array,columns=['代码', '名称','价格','涨幅','量比','换手率','结论'])
formatted_time = datetime.now().strftime("%Y-%m-%d_%H-%M");
monitor_daily_directory = get_directory(_base_directory,_daily_directory)
file_path = os.path.join(monitor_daily_directory, formatted_time+".csv")
rs.to_csv(file_path, index=False)